package com.jk.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.jk.dao.ShopDao;
import com.jk.entity.ClothEntity;
import com.jk.entity.UserEntity;
import com.jk.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Set;

/**
 * @详细介绍类情况.
 * @ClassName ShopServiceImpl
 * @Author 张荣鑫
 * @Date 2022/6/2
 * @Version 1.0
 */
@Service
@SuppressWarnings("all")
public class ShopServiceImpl implements ShopService {
    @Autowired
    private ShopDao shopDao;
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * @方法名称:查询新品列表
     * @author 张荣鑫
     * @return java.lang.Object
     * @exception
     * @date 2022/6/2 10:14
     */
    @Override
    public HashMap<String, Object> queryAllShop(String name) {


        List<ClothEntity>list=shopDao.queryAllShop(name);

        HashMap<String, Object> map = new HashMap<>();

        map.put("list",list);
        return map;
    }

    /**
     * @方法名称:查看商品
     * @author 张荣鑫
     * @return java.lang.Object
     * @exception
     * @date 2022/6/6 10:30
      * @param shopId
     */
    @Override
    public Object getShopBynum(Integer shopId) {
        ClothEntity clothEntity=shopDao.getShopBynum(shopId);
        return clothEntity;
    }

    /**
     * @方法名称:添加购物车
     * @author 张荣鑫
     * @exception
     * @date 2022/6/6 15:43
     * @param shopId
     * @param num
     */
    @Override
    public String addshopCar(Integer shopId, Integer num) {
    String str="";
        String key = "login";
        String  json = (String) redisTemplate.opsForValue().get(key);
        UserEntity userEntity = JSONObject.parseObject(json, UserEntity.class);

        ClothEntity clothEntity = shopDao.queryshopByid(shopId,userEntity.getUserId());

        if (num == null) {
            num=1;
        }
        if (clothEntity == null) {
            shopDao.addshopCar(userEntity.getUserId(),shopId,num);
            str = "加入购物车成功";
        }else {
            shopDao.updateCount(userEntity.getUserId(),shopId,num);
            str = "购物车数量+1";
        }
        return str;
        }

        /**
         * @方法名称:查询男子商品列表
         * @author 张荣鑫
         * @return java.util.HashMap<java.lang.String, java.lang.Object>
         * @exception
         * @date 2022/6/7 14:12
          * @param num
         */
    @Override
    public HashMap<String, Object> queryManShop( ) {
        int total=shopDao.getcount2();

        List<ClothEntity>list=shopDao.queryManShop();

        HashMap<String, Object> map = new HashMap<>();
        map.put("total",total);
        map.put("list",list);
        return map;
    }

    /**
     * @方法名称:查询女子商品列表
     * @author 张荣鑫
     * @return java.util.HashMap<java.lang.String, java.lang.Object>
     * @exception
     * @date 2022/6/7 14:45
     */
    @Override
    public HashMap<String, Object> queryWomanShop() {
        int total=shopDao.getcount3();

        List<ClothEntity>list=shopDao.queryWomanShop();

        HashMap<String, Object> map = new HashMap<>();
        map.put("total",total);
        map.put("list",list);
        return map;
    }

    /**
     * @方法名称:查询特价商品
     * @author 张荣鑫
     * @return java.util.HashMap<java.lang.String, java.lang.Object>
     * @exception
     * @date 2022/6/9 11:18
     * @param
     */
    @Override
    public HashMap<String, Object> querytejia() {
        int total=shopDao.getcount4();

        List<ClothEntity>list=shopDao.querytejia();

        HashMap<String, Object> map = new HashMap<>();
        map.put("total",total);
        map.put("list",list);
        return map;
    }


}